<template>
	<view class="content">
		<view class="personal_zl" @tap="modify">
			<view class="personal_zl_left">
				<text class="name">{{user_info.nickname?user_info.nickname:user_info.phone}}</text>
				<text style="padding-top: 10rpx;">{{user_info.signature?user_info.signature:"这个人很懒..什么也没留下"}}</text>
			</view>
			<image class="personal_zl_img" :src="user_info.avatar_url?user_info.avatar_url:'/static/images/user_img.jpg'"></image>
		</view>
		<view class="release_box">
			<view class="release_ul">
				<view class="release_ul_li" >
					<text class="num">{{customer_data.publish}}</text>
					<text>发布</text>
				</view>
				
				<view class="release_ul_li" >
					<text class="num">{{customer_data.ywc}}</text>
					<text>已完成</text>
				</view>
				
				<view class="release_ul_li" >
					<text class="num">{{customer_data.dwc}}</text>
					<text>待完成</text>
				</view>
			</view>
			<button @tap="orderAll">查看订单</button>
		</view>
		<view class="list_box">
			<view class="list_box_li" @tap="orderAll">
				<image src="../../../static/images/user_my03.png"></image>
				<text>我的订单</text>
			</view>
			<view class="list_box_li" @tap="coupons">
				<image src="../../../static/images/user_my02.png"></image>
				<text>优惠券</text>
			</view>
			<view class="list_box_li"  @tap="contact">
				<image src="../../../static/images/user_my04.png"></image>
				<text>我的地址</text>
			</view>
			<view class="list_box_li" @tap="dialPhone">
				<image src="../../../static/images/user_my01.png"></image>
				<text>在线客服</text>
			</view>
			<view class="list_box_li border-no" @tap="merchant">
				<image src="../../../static/images/user_my05.png"></image>
				<text>进入商户端</text>
			</view>
			<loginModel v-if="!is_login" @getUerInfoSucc="get_user_info_succ"></loginModel>
		</view>
		
	</view>
</template>

<script>
	import loginModel from "../../../components/login_model/login_model.vue";
	export default {
		data() {
			return {
				is_login:false,
				user_info:'',
				customer_data:''
			};
		},
		components:{
			loginModel
		},
		onShow() {
			let token = uni.getStorageSync("token");
			if(token){
				this.is_login = true;
				this.get_server_user_info()
			}
		},
		methods:{
			//修改个人资料
// 			modify(){
// 				uni.navigateTo({
// 					url:'../modifyPer/modifyPer'
// 				})
// 			},
			// 从服务器获取用户数据
			get_server_user_info(){
				this.$ajax.post({url:'/User/getUserInfo'}).then(res=>{
					console.log(res)
					if(res.code==200){
						this.user_info = res.data.userData;
						this.customer_data = res.data.customer
					}else{
						this.$alert(res.msg)
					}
				})
			},
			// 获取微信用户信息成功
			get_user_info_succ(e){
		 
					uni.login({
						success:(res)=> {
							if(e){
								e.code=res.code
								this.do_login(e) 
							}
						}
					})
		 
				
			},
			
			do_login:async function(e){
		 
				let data = {
					code:e.code,
					encryptedData:e.encryptedData,
					iv:e.iv
				}
	 
				let res = await this.$ajax.post({url:'/Login/login',data});
				
				if(res.code==200){
					this.is_login = true;
					this.$alert(res.msg);
					
					uni.setStorageSync("token",res.data.access_token)
					this.get_server_user_info()
				}else{
					this.$alert(res.msg);
				}
			},
			//订单列表
			orderAll(evt){
				var id = evt.currentTarget.dataset.id;
				console.log(id)
				uni.navigateTo({
					url:'../order/order?id=' + id
				})
			},
			//优惠券
			coupons(){
				uni.navigateTo({
					url:'../coupons/coupons'
				})
			},
			//地址列表
			contact() {
				uni.navigateTo({
					url: '/pages/address_manager/list'
				})
			},
			//进入商户
			merchant(){
				uni.navigateTo({
					url: '../../merchants/merchindex/merchindex'
				})
			},
			dialPhone(){
				uni.makePhoneCall({
					phoneNumber: '18235461258' 
				});
			},

		}
	}
</script>

<style>
.content{
	box-shadow:0 8px 10px -8px #eee inset;
	border-top: 1px solid #eee;
}
.personal_zl{
	padding: 70upx 40upx 0;
	display: flex;
	justify-content: space-between;
	box-sizing: border-box;
}
.personal_zl_left{
	display: flex;
	flex-direction: column;
	color: #a4a8b4;
	font-size: 24upx;
	width: 550upx;
}
.personal_zl_left .name{
	color: #41434b;
	font-size: 40upx;
}
.personal_zl_img{
	height: 120upx;
	width: 120upx;
	border-radius: 50%;
}
.release_box{
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 40upx 20upx;
	box-sizing: border-box;
	border-bottom: 20upx solid #ebedf5;
}
.release_ul{
	display: flex;
	
}
.release_ul_li{
	display: flex;
	flex-direction: column;
	align-items: center;
	text-align: center;
	width: 90upx;
	color: #a4a8b4;
	font-size: 24upx;
}
.release_ul_li .num{
	font-size: 60upx;
	font-weight: 600;
	color: #41434b;
}
.release_box button{
	background: #fff;
	border: 1px solid #41434b;
	border-radius: 50upx;
	padding: 0;
	height: 50upx;
	line-height: 50upx;
	box-sizing: border-box;
	font-size: 24upx;
	width:160upx;
	margin: 0 20upx;

}
.list_box{
	padding: 0 40upx;
	box-sizing: border-box;
}
.list_box_li{
	display: flex;
	border-bottom: 1px solid #eee;
	line-height: 90upx;
	font-size: 28upx;
	align-items: center;
	font-weight: 600;
	color: #41434b;
}
.list_box_li image{
	height: 45upx;
	width: 45upx;
	margin-right: 20upx;
}
</style>
